package cn.tedu.charging.user.controller;


import cn.tedu.charging.user.pojo.vo.UserAndVehicle;
import cn.tedu.charging.user.service.UserService;
import cn.tedu.common.pojo.JsonResult;
import cn.tedu.common.pojo.vo.UserInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户接口")
@Slf4j
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("获取用户信息")
    @GetMapping("/info/{userId}")
    public JsonResult<UserInfoVO> getUserInfo(@PathVariable("userId") Integer userId) {
        log.debug("获取用户信息:{}", userId);
        UserInfoVO userInfoVO = userService.getUserInfo(userId);
        /*JsonResult<UserInfoVO> jsonResult = new JsonResult<>();
        jsonResult.setCode(2000); //统一状态码 2000表示成功
        jsonResult.setData(userInfoVO);
        jsonResult.setMessage("获取用户信息成功");//一般消息在报错的时候返回*/
        JsonResult<UserInfoVO> result = JsonResult.ok(userInfoVO, "获取用户信息成功");
        return JsonResult.ok(userInfoVO, "获取用户信息成功");
    }

    @ApiOperation("查询车辆信息")
    @GetMapping("/Carinfo/{id}")
    public JsonResult<UserAndVehicle> getCarInfo(@PathVariable("id") Integer id) {
        log.debug("获取车辆信息:{}", id);
        UserAndVehicle userAndVehicle = userService.getCarInfo(id);
        return JsonResult.ok(userAndVehicle, "获取车辆信息成功");
    }
}
